package com.villaday.idf.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.villaday.idf.R;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.OnAdapterCallbackListener;
import com.villaday.idf.model.HousesStates;
import com.villaday.idf.util.PhoneUtil;


public class DateCheckInAdapterForTemai extends AbsRecyclerViewAdapter<HousesStates.BodyEntity.MonthsEntity.ListEntity> {
    private OnAdapterCallbackListener onAdapterCallbackListener;
    private View.OnClickListener onClickListener;
/*
    private final String roleType;
*/

    public DateCheckInAdapterForTemai(Context context, View.OnClickListener onClickListener) {
        super(context, R.layout.item_calendar_inner_for_te_mai, R.layout.item_calendar_inner1, R.layout.item_page_loading,
                R.layout.item_page_bottom);
        this.onClickListener = onClickListener;
       /* RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(context);
        roleType = roleInfo.getMember().getType();*/

    }

    @Override
    public int getItemType(HousesStates.BodyEntity.MonthsEntity.ListEntity d) {
        return d.getMyType() == 1 ? 1 : 0;
    }

    @Override
    public void onBindHolder(AbsRecyclerViewAdapter.RecyclerViewHolder holder, HousesStates.BodyEntity.MonthsEntity.ListEntity d, int position) {
        if (d.getMyType() == 1) {
            LinearLayout ll = (LinearLayout) holder.getView(R.id.ll);
            ViewGroup.LayoutParams layoutParams = ll.getLayoutParams();
            layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;

            layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
            ll.requestLayout();
        } else {
            RelativeLayout ll = (RelativeLayout) holder.getView(R.id.ll);
            ViewGroup.LayoutParams layoutParams = ll.getLayoutParams();
            layoutParams.height = context.getResources().getDisplayMetrics().widthPixels / 7 + 1;
            layoutParams.width = context.getResources().getDisplayMetrics().widthPixels / 7 + 1;
            if (ll.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
                ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) ll.getLayoutParams();
                p.setMargins(0, 0, 0, PhoneUtil.dp2px(context, 3));
            }


            ll.requestLayout();

        }

        if (d.getMyType() == 0) {
            TextView tv = (TextView) holder.getView(R.id.name);
            if (d.getStatus() == 4) {
                tv.setTextColor(Color.parseColor("#999999"));
            } else {
                tv.setTextColor(Color.parseColor("#F73637"));

            }
            holder.setClickListenerAndTag(R.id.ll, onClickListener, position)
                    .bindTextView(R.id.name, d.getDayOfMonth() + "")
                    .bindTextViewWithHtml(R.id.type, d.getStatus() == 1 ? "&yen;" + PhoneUtil.handleBalance((d.getCurrentPrice() / 100.0) + "", 0) : d.getStatusText() + "");
            RelativeLayout view = (RelativeLayout) holder.getView(R.id.ll);
            if (d.getSelectType() == 0) {
                view.setBackgroundColor(context.getResources().getColor(R.color.colorWhite));
                holder.bindTextView(R.id.name, d.getDayOfMonth() + "");
                tv.setTextColor(Color.parseColor("#333333"));
            } else if (d.getSelectType() == 1) {
                //holder.bindTextView(R.id.name, "入住");
                ///view.setBackgroundResource(R.drawable.shape_solid_red_5500);
                view.setBackgroundResource(R.drawable.shape_red_90);

                tv.setTextColor(Color.parseColor("#ffffff"));
                ((TextView)holder.getView(R.id.type)).setTextColor(Color.parseColor("#ffffff"));
            } else if (d.getSelectType() == 3) {
                holder.bindTextView(R.id.name, "离开");
                //view.setBackgroundResource(R.drawable.shape_solid_red_0055);
                view.setBackgroundResource(R.drawable.shape_red_009090);

                tv.setTextColor(Color.parseColor("#ffffff"));

            } else if (d.getSelectType() == 2) {
                holder.bindTextView(R.id.name, d.getDayOfMonth() + "");
                //view.setBackgroundColor(context.getResources().getColor(R.color.dateColorPink));
                view.setBackgroundColor(context.getResources().getColor(R.color.title_bg2));


                tv.setTextColor(Color.parseColor("#333333"));

            } else if (d.getSelectType() == 4) {
                view.setBackgroundResource(R.drawable.shape_red_909000);

                holder.bindTextView(R.id.name, "入住");

                tv.setTextColor(Color.parseColor("#ffffff"));
            }

        } else if (d.getMyType() == 1) {
            holder.bindTextView(R.id.tv_month, d.getDate().substring(0, 7));

        } else {
            TextView tv = (TextView) holder.getView(R.id.name);
            if (d.getStatus() == 4) {
                tv.setTextColor(Color.parseColor("#999999"));
            } else {
                tv.setTextColor(Color.parseColor("#333333"));

            }
            holder.setClickListenerAndTag(R.id.ll, null, position)
                    .bindTextView(R.id.name, "")
                    .bindTextViewWithHtml(R.id.type, "");
            RelativeLayout view = (RelativeLayout) holder.getView(R.id.ll);

            view.setBackgroundColor(context.getResources().getColor(R.color.colorWhite));


        }

    }


}
